package com.pxmeta.app.controller.web;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.google.common.collect.Maps;
import com.pxmeta.app.controller.web.response.ShareChatGroupDetailVO;
import com.pxmeta.app.controller.web.response.SharePartyDetailVO;
import com.pxmeta.chat.entity.ChatGroup;
import com.pxmeta.chat.service.IChatGroupService;
import com.pxmeta.common.core.domain.AjaxResult;
import com.pxmeta.common.utils.SecurityUtils;
import com.pxmeta.party.entity.Party;
import com.pxmeta.party.service.IPartyService;
import com.pxmeta.user.entity.User;
import com.pxmeta.user.entity.vo.ShareRewardVO;
import com.pxmeta.user.service.IShareRewardService;
import com.pxmeta.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.compress.utils.Lists;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 移动 h5 前端控制器
 */
@RestController
@Api(value = "分享",tags = "分享")
@RequiredArgsConstructor
@RequestMapping("/share")
@CrossOrigin
public class ShareController {

    private final IChatGroupService chatGroupService;
    private final IUserService userService;
    private final IPartyService partyService;
    private final IShareRewardService shareRewardService;


    @ApiOperation("获取分享群聊详情")
    @GetMapping("/getChatGroupDetail")
    public AjaxResult<ShareChatGroupDetailVO> getChatGroupDetail(@RequestParam Long chatGroupId,
                                                                 @RequestParam Long userId){
        ChatGroup chatGroup = chatGroupService.getById(chatGroupId);
        User user = userService.getById(userId);
        ShareChatGroupDetailVO result = ShareChatGroupDetailVO.builder().chatGroupName(chatGroup.getGroupName())
                .chatGroupAvatar(chatGroup.getAvatar())
                .avatar(user.getAvatar())
                .nickname(user.getNickname())
                .content("我发现了一个超有趣的群聊\n" +
                        "邀请你一起来玩")
                .build();

        return AjaxResult.success(result);
    }

    @GetMapping("/getShareContent")
    @SaCheckLogin
    @ApiOperation("获取分享说明")
    public AjaxResult getShareContent(){
        HashMap<String, Object> map = Maps.newHashMap();
        map.put("title","碰心币能干什么？");
        ArrayList<String> list = Lists.newArrayList();
        list.add("直播间礼物打赏");
        list.add("聊天搭讪");
        list.add("购买头像框等虚拟商品");
        map.put("content",list);

        return AjaxResult.success(map);
    }


    @GetMapping("/getShareRewards")
    @ApiOperation("获取分享奖励列表")
    @SaCheckLogin
    public AjaxResult<ShareRewardVO> getShareRewards(){
        Long userId = SecurityUtils.getUserId();
        ShareRewardVO vo = shareRewardService.getShareRewards(userId);
        return AjaxResult.success(vo);
    }


    @ApiOperation("获取派对详情")
    @GetMapping("/getPartyDetail")
    public AjaxResult getPartyDetail(@RequestParam String partyId){
        Party party = partyService.getById(partyId);
        User user = userService.getById(party.getUserId());
        SharePartyDetailVO vo = SharePartyDetailVO.builder().avatar(user.getAvatar())
                .nickname(user.getNickname())
                .partyName(party.getTitle())
                .partyNumber(party.getNumber()).build();
        return AjaxResult.success(vo);
    }
}
